package user

import (
	"context"
	upbv1 "jmicro/api/user/v1"
	"jmicro/app/user/srv/internal/domain/dto"
	metav1 "jmicro/pkg/common/meta/v1"
	"jmicro/pkg/log"
)

func DTOToResponse(userdto dto.UserDTO) upbv1.UserInfoResponse {
	return upbv1.UserInfoResponse{}
}

/*
controller层依赖了service层，service层依赖了data层：
contoller层能否直接依赖data层：可以的
contoller依赖service层，并不是直接依赖了具体的struct 而是依赖了interface，
但是底层是绝对不能依赖父层的！
*/

func (us *userServer) GetUserList(ctx context.Context, info *upbv1.PageInfo) (*upbv1.UserListResponse, error) {
	log.Info("GetUserList is called")
	srvOpts := metav1.ListMeta{
		Page:     int(info.Pn),
		PageSize: int(info.PSize),
	}
	dtoList, err := us.srv.List(ctx, srvOpts)
	if err != nil {
		return nil, err
	}
	var rsp = upbv1.UserListResponse{Total: int32(dtoList.TotalCount)}
	for _, value := range dtoList.Items {
		//userRsp := DTOToResponse(*value)
		rsp.Data = append(rsp.Data, &upbv1.UserInfoResponse{
			NickName: value.NickName,
		})
	}
	rsp.Total = int32(dtoList.TotalCount)
	return &rsp, nil
}
